#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from time import sleep
'''
fork 4个子进程来处理请求
'''
pid_list = []
def fork_num(num=1):
    pid = os.fork()
    if pid > 0:   #父进程
        print("master process, pid %d"%os.getpid())
        num -= 1
        if num > 0: fork_num(num)
    elif pid == 0:   #子进程
        for i in range(10):
            print("worker process, pid %d, ppid %d"%(os.getpid(),os.getppid()))
            sleep(1)
        pid_list.append(os.getpid())
    else:
        print("fork error")
fork_num(4)
sleep(2)
for pid in pid_list:
    print("subprocess: %d is running"%pid)


